package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsLink;
import com.example.demo.bean.CmsMember;
import com.example.demo.common.Respones;
import com.example.demo.service.CmsLinkService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "链接管理服务")
@RestController
@RequestMapping("/link")
public class CmsLinkController {
	@Autowired
	private CmsLinkService linkservice;
	
	
	//按链接编号删除链接信息
		@ApiOperation(value = "按照链接编号，删除链接信息！")
		@DeleteMapping("/deleteById")
		public Respones<Integer> deleteById(Integer id){
			int count = linkservice.deleteById(id);
			return Respones.ok(1 + count);	
		}
	
	
	
	
	//保存或者更新会员信息
		@ApiOperation(value = "保存或者更新链接信息",
				notes = "如果传递参数时没有指明链接编号，那么执行插入操作")
		@PostMapping("/saveOrUpdateLink")
		public Respones<Integer> saveOrUpdate(CmsLink link){
		boolean b= linkservice.saveOrUpdateCmsLink(link);
		if(b)	return Respones.ok(1);
		else return Respones.error(0);
			
		}
	
	
	//获取所有链接信息
		@ApiOperation(value = "获取所有链接信息",notes="从数据库检索所有链接信息")
		@GetMapping("/all")
		public Respones<List<CmsLink>> queryAll(){
			//调用业务方法
			List<CmsLink> cl=linkservice.getAllLink();
			return Respones.ok(cl);
		}
	

}
